package application

import (
	"context"
	"forum/intr/domain"
	"forum/intr/domain/repo"
)

var _ InteractiveService = &InteractiveServiceImp{}

//go:generate mockgen -source=./intr.go -package=svcmocks -destination=./mocks/interactive_gen.go
type InteractiveService interface {
	Get(ctx context.Context, biz string, id int64, uid int64) (domain.Interactive, error)
	IncrReadCnt(ctx context.Context, biz string, id int64) error
	Like(ctx context.Context, biz string, id int64, uid int64) error
	CancelLike(ctx context.Context, biz string, id int64, uid int64) error
	Collect(ctx context.Context, biz string, id int64, uid int64) error
	CancelCollect(ctx context.Context, biz string, id int64, uid int64) error
}

func NewInteractiveServiceImp(interRepo repo.InteractiveRepository) *InteractiveServiceImp {
	return &InteractiveServiceImp{interRepo: interRepo}
}

type InteractiveServiceImp struct {
	interRepo repo.InteractiveRepository
}

func (i *InteractiveServiceImp) Like(ctx context.Context, biz string, id int64, uid int64) error {
	return i.interRepo.IncrLike(ctx, biz, id, uid)
}

func (i *InteractiveServiceImp) CancelLike(ctx context.Context, biz string, id int64, uid int64) error {
	return i.interRepo.DecrLike(ctx, biz, id, uid)
}

func (i *InteractiveServiceImp) Collect(ctx context.Context, biz string, id int64, uid int64) error {
	return i.interRepo.IncrCollect(ctx, biz, id, uid)
}

func (i *InteractiveServiceImp) CancelCollect(ctx context.Context, biz string, id int64, uid int64) error {
	return i.interRepo.DecrCollect(ctx, biz, id, uid)
}

func (i *InteractiveServiceImp) Get(ctx context.Context, biz string, id int64, uid int64) (domain.Interactive, error) {
	return i.interRepo.GetById(ctx, biz, id, uid)
}

func (i *InteractiveServiceImp) IncrReadCnt(ctx context.Context, biz string, id int64) error {
	return i.interRepo.IncrReadCnt(ctx, biz, id)
}
